﻿using System;

namespace Solution
{
    public class StandardResult : IStandardResult
    {
        #region 公共属性

        public string Message
        {
            get; set;
        }

        public int State
        {
            get; set;
        }

        #endregion 公共属性

        #region 公共方法

        public void Fail()
        {
            this.State = 1;
        }

        public void Fail(string message)
        {
            this.State = 1;
            this.Message = message;
        }

        public void Succeed()
        {
            this.State = 0;
        }

        public void Succeed(string message)
        {
            this.State = 0;
            this.Message = message;
        }
        public void Try(Action action)
        {
            try
            {
                action();
                this.Succeed();
            }
            catch (ShowException ex)
            {
                this.Fail(ex.Message);
            }
            catch (Exception ex)
            {
                this.Fail(ExceptionExtension.GetAllMessages(ex));
            }
        }

        #endregion 公共方法
    }

    public class StandardResult<T> : StandardResult, IStandardResult<T>
    {
        #region 公共属性

        public T Value
        {
            get; set;
        }

        #endregion 公共属性
    }
}